<template>
    <div id="pc-header">

        <!-- 手机端导航 -->
        <div class="nav_mobile mobile" v-show="navIsShowMobile">
            <div class="nav">
                <div class="hide_nav" @click="mobileNavShow">X</div>
                <!-- 已登录 -->
                <div class="mobile_login" v-if="webIsLogin()" @click="loginInfoClick">
                    <span class="avatar">
                        <img :src="imgDomainUrl + webLoginAvatar" class="img100" alt="avatar">
                    </span>
                    <span class="nickname">{{ webLoginNickname }}</span>
                </div>
                <!-- 未登录 -->
                <div class="mobile_login" v-if="!webIsLogin()">
                    <span class="avatar">
                        <router-link :to="{ name: 'web_login' }"><img src="@/assets/img/web/user/user_unlogin_avatar.png" class="img100" alt="avatar"></router-link>
                    </span>
                    <span class="nickname"><router-link :to="{ name: 'web_login' }">未登录</router-link></span>
                </div>

                <span class="nav_list_span" @click="mobileNavShow()">
                    <nav-list :webNavSelected="webNavSelected" />
                </span>

                <!-- 已登录 -->
                <div class="login_logout" v-if="webIsLogin()">
                    <span @click="webLogout()">退出登录</span>
                </div>
                <!-- 未登录 -->
                <div class="login_logout" v-if="!webIsLogin()">
                    <span><router-link :to="{ name: 'web_login' }">登录</router-link></span>
                    <span>&nbsp;/&nbsp;</span>
                    <span><router-link :to="{ name: 'web_register' }">注册</router-link></span>
                </div>

            </div>
        </div>
        <!-- PC端导航，有部分内容mobile也用到了 -->
        <div class="pc-header w-fixed-center">
            <div class="logo">
                <img src="@/assets/img/logo.png" class="img100" alt="logo">
            </div>
            <div class="nav_pc pc">
                <div class="nav">
                    <nav-list :webNavSelected="webNavSelected" />
                </div>
            </div>
            <div class="header_right">
                <!-- 未登录 -->
                <div class="user unlogin" v-if="!webIsLogin()">
                    <router-link :to="{ name: 'web_login' }">登录</router-link>
                    <router-link class="pc" :to="{ name: 'web_register' }">注册</router-link>
                </div>
                <!-- 已登录 -->
                <div class="user login" v-if="webIsLogin()" @click="loginInfoClick">
                    <span class="avatar">
                        <img :src="imgDomainUrl + webLoginAvatar" class="img100" alt="avatar">
                    </span>
                    <span class="pc">{{ webLoginNickname }}</span>
                </div>
                <!-- mobile，显示导航菜单的小按钮 -->
                <div class="mobile_nav mobile">
                    <img src="@/assets/img/web/mobile_show_nav.png" class="icon" alt="nav" @click="mobileNavShow">
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { reactive, ref, inject } from 'vue';
import { webNavSelected } from '@/store/webNavSelected.js';
import navList from '@/components/web/nav_list.vue';  //导航列表

const { imgDomainUrl } = inject('imgDomainUrl');  // 依赖注入--文件、图片前的域名
const { webIsLogin } = inject('webIsLogin');  // 依赖注入--是否已登录（true、false）
const { webLogout } = inject('webLogout');  // 依赖注入--退出登录
const { webLoginNickname, webLoginEmail, webLoginAvatar, webLoginMobile } = inject('webLoginInfo');  // 依赖注入--是否已登录（true、false）
const { doRedirectByName } = inject('doRedirectByName');  // 依赖注入--跳转到其他页面（根据命名路由跳转）

// 右上角，用户信息点击事件
const loginInfoClick = () => {
    doRedirectByName('web_my');
}

const navIsShowMobile = ref(false);  // 导航栏是否显示（true、false）
// 手机端导航栏点击事件--显示导航菜单
const mobileNavShow = () => {
    navIsShowMobile.value = !navIsShowMobile.value;
}
</script>

<style scoped>
#pc-header {
    width: 100%;
    background-color: #fff;
    border-bottom: 1rem solid #e5e5e5;
}

.pc-header {
    height: 60rem;
    /* background-color: #333; */
    color: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20rem;

    font-weight: bold;
}

.logo {
    width: 150rem;
    height: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
}

.logo img {
    width: 100%;
    height: 50rem;
}

.nav_pc {
    height: 100%;
}

.nav {
    width: 790rem;
    display: flex;
    justify-content: left;
    align-items: center;
    padding-left: 100rem;
    overflow-x: hidden;
    color: #333;
    height: 100%;
}

.user {
    width: 300rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.unlogin>a {
    color: #333;
    font-weight: bold;
    text-decoration: none;
    padding: 0 10rem;
    font-size: 16rem;
}

.login>span {
    color: #333;
    font-weight: bold;
    text-decoration: none;
    cursor: pointer;
}

.login>.avatar {
    width: 40rem;
    height: 40rem;
    border-radius: 50%;
    margin-right: 10rem;
}

/*手机端样式*/
@media screen and (max-width: 800px) {
    #pc-header {
        background-color: #0C48C9;
        /* position: fixed;
        top: 0;
        left: 0;
        right: 0; */
        z-index: 999;
    }

    .pc-header {
        height: 56rem;
        padding: 0;
    }

    .logo img {
        height: 40rem;
    }

    .header_right {
        display: flex;
        align-items: center;
    }

    .nav_mobile {
        z-index: 6;
        width: 100%;
        position: fixed;
        top: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.6);
    }

    .nav {
        width: 270rem;
        background-color: #fff;
        flex-direction: column;
        padding-left: 20rem;
        padding-top: 20rem;
        padding-right: 20rem;
        overflow-y: auto;
        float: right;
        position: relative;
    }

    .nav .hide_nav {
        position: absolute;
        right: 10rem;
        top: 15rem;
        font-size: 20rem;
        color: #333;
    }

    .nav .mobile_login {
        display: flex;
        flex-direction: column;
        padding-bottom: 20rem;
        border-bottom: 1rem solid #e8e8e8;
        width: 100%;
        margin-bottom: 20rem;
    }

    .nav .mobile_login .avatar {
        margin: 0 auto;
        width: 50rem;
        height: 50rem;
        display: inline;
    }

    .nav .mobile_login .nickname {
        margin-top: 10rem;
        text-align: center;
    }
    .nav .mobile_login .nickname a {
        color: #333;
    }

    .nav .login_logout {
        background-color: #0C48C9;
        border-radius: 3rem;
        margin-top: 80rem;
        width: 100%;
        height: 36rem;
        line-height: 36rem;
        text-align: center;
        font-size: 12rem;
        text-align: center;
    }
    
    .nav .login_logout span,a {
        color: #fff;

    }

    .nav .nav_list_span {
        display: flex;
        width: 100%;
        flex-direction: column;
        align-items: center;
    }

    .user {
        width: auto;
        color: #fff;
        margin-right: 10rem;
    }

    .unlogin>a {
        color: #fff;
    }

    .login>.avatar {
        width: 30rem;
        height: 30rem;
    }

    .mobile_nav {
        display: flex;
        height: 100%;
        align-items: center;
    }

    .mobile_nav .icon {
        width: 20rem;
        height: 20rem;
    }
}
</style>